package demo.bean;

import java.io.Serializable;
import java.util.Map;
import java.util.Set;

public class Carts implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4851643944613925238L;
	private Map<Goods,Integer> buygood;
	private String username;
	private double total;
	
	
	public Carts(Map<Goods,Integer> buygood,String username)
	{
		double t=0;
		Set<Map.Entry<Goods,Integer>> set=buygood.entrySet();
		for(Map.Entry<Goods,Integer> a:set)
		{
			Goods d=a.getKey();
			t+=d.getPeice()*a.getValue();
		}
		this.buygood=buygood;
		this.total=t;
		this.username=username;
	}

	public Map<Goods, Integer> getBuygood() {
		return buygood;
	}




	public void setBuygood(Map<Goods, Integer> buygood) {
		this.buygood = buygood;
	}




	public String getUsername() {
		return username;
	}




	public void setUsername(String username) {
		this.username = username;
	}




	public double getTotal() {
		return total;
	}




	public void setTotal(double total) {
		this.total = total;
	}




	@Override
	public String toString() {
		Set<Map.Entry<Goods,Integer>> set=buygood.entrySet();
		for(Map.Entry<Goods,Integer> a:set)
		{
			Goods d=a.getKey();
			System.out.println("商品名称："+d.getName()+"|商品价格："+d.getPeice()+"|商品购买数目："+a.getValue()+"|商品库存："+(d.getNumber()-a.getValue()));
		}
		
		return "--用户名字:"+username+"|所有商品总价格："+total;
	}
	
	
	
	

}
